# -*-coding: Utf-8 -*-
# @File : log
# author: liaohf
# Time：2024/9/21
from core.Response import success, fail
from database.models.base import CaseLog
from schemas import log
from fastapi import APIRouter

router = APIRouter()


@router.post("/addLog", summary="日志添加")
async def add_log(post: log.Log):
    """
    日志添加
    :param post:Log
    :return:
    """
    # 添加日志
    sql_add_log = await CaseLog.create(**post.dict())
    if not sql_add_log:
        return fail(msg=f"添加日志失败!")
    return success(msg=f"添加日志成功!")


@router.get("/getCaseLogListByRunId", summary="获取日志")
async def get_case_log_list_by_run_id(run_id):
    """
    获取日志
    :param run_id: Log
    :return:
    """
    # 获取日志
    sql_get_log = await CaseLog.filter(run_id=run_id).all().values('case_id', 'run_id', 'content', 'log_level')
    if not sql_get_log:
        return fail(msg=f"获取日志失败!")
    return success(msg=f"获取日志成功!", data=sql_get_log)
